package com.shangxia.monomer.study.designPatterns.behavioralType.strategy;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

/**
 * @ProjectName: monomer
 * @ClassName: StrategyOptimization
 * @Time: 2021/7/25
 * @Author: zhouy
 * @Description:
 * @Experience:
 */

@Slf4j
public class StrategyOptimization {
    public static void main(String[] args) {
        List<ZombieA> list = new ArrayList<>();
        list.add(new ZombieA("001", new Zou(), new PuTongGongJi()));
        list.add(new ZombieA("002", new Fei(), new JiNengGongJi()));
        list.add(new ZombieA("003", new Zou(), new JiNengGongJi()));
        for (ZombieA zombie : list) {
            zombie.show();
            zombie.move();
            zombie.attach();
        }
    }
}

@AllArgsConstructor
@Data
class ZombieA {
    private String name;
    private MoveAble moveAble;
    private AttachAble attachAble;

    void show() {
        System.out.println("I am " + getName());
    }

    void move() {
        moveAble.move();
    }

    void attach() {
        attachAble.attach();
    }
}

interface MoveAble {
    void move();
}

interface AttachAble {
    void attach();
}

class Zou implements MoveAble {

    @Override
    public void move() {
        System.out.println("走");
    }
}

class Fei implements MoveAble {

    @Override
    public void move() {
        System.out.println("飞");
    }
}

class PuTongGongJi implements AttachAble {

    @Override
    public void attach() {
        System.out.println("普通攻击");
    }
}

class JiNengGongJi implements AttachAble {

    @Override
    public void attach() {
        System.out.println("普通攻击");
    }
}